import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const TOKEN=uni.getStorageSync("token") || ''
const ISSIGN=uni.getStorageSync("is_sign") || ''
const USER_INFO = uni.getStorageSync("userInfo") || ''
const USER_LISTS = uni.getStorageSync("userLists") || '' // 切换账号

const store = new Vuex.Store({
	state:{
		isShowLoading:false,
		isShowfinshed:false,
		token:TOKEN,  //登录token
		is_sign:ISSIGN,
		user_info:USER_INFO,// 用户信息
		//存储购物车选中的商品购物车id
		selectShopCarList:'',
		userLists:USER_LISTS,
		chooseAddressId:'',
		chooseBankCardId:''
	},
	getters:{
		hasLogin:(state)=>{
		   if(state.token){
			   return true
		   }else {
			   return false
		   }
		},
		hasCheck:(state)=>{
			if(state.is_sign){
				return true
			}else {
				return false
			}
		}
	},
	mutations:{
		//修改加载中状态
		CHANGESHOWlOADING(state,data){
			state.isShowLoading=data
		},
		//修改无更多数据状态
		CHANGESHOWFINSHED(state,data){
			state.isShowfinshed=data
		},
		//设置TOKEN
		SETTOKEN(state,data){
		  state.token=data
		  uni.setStorageSync("token",data)
		},
		SET_USERINFO(state, userInfo) {
			state.user_info = userInfo;
			uni.setStorageSync("userInfo", userInfo);
		},
		//修改购物车选中的商品
		CHANGESHOPCARLIST(state,data){
			state.selectShopCarList=data
		},
		//修改购物车选中的商品
		CHANGEADDRESSID(state,data){
			state.chooseAddressId=data
		},
		//修改购物车选中的商品
		CHANGEBANKCARDID(state,data){
			state.chooseBankCardId=data
		},
	},
	actions:{

	}
})

export default store
